﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SimCMS.Manager;
using SimCMS.Model;

namespace SimCMS.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        public ISimadminManager SimadminManager { get; set; }
        public ISimadminmenuManager SimadminmenuManager { get; set; }
        public ISimadminroleManager SimadminroleManager { get; set; }

        public ActionResult Index()
        {
            // SimadminManager.Save(new Simadmin { UserName="abcd",Password="453" });
            //var ListPanel = new List<Simadminpanel>();
            //var mm = new Simadminpanel
            //{
            //    MenuDatetime = DateTime.Now,
            //    Name = "test"
            //};
            //ListPanel.Add(mm);
            //var admin = new Simadmin
            //{
            //    UserName = "abcd",
            //    Password = "453",
            //    Simadminpanel = ListPanel
            //};
            //admin.Simadminrole = SimadminroleManager.Get(1);
            //mm.Simadmin = admin;
            //SimadminManager.Save(admin);
            //ViewData["Company"] = SimadminManager.LoadAll();

            return View(SimadminmenuManager.LoadAll().Where(o=>o.Display==true).ToList());
        }

        //[AcceptVerbs(HttpVerbs.Post)]
        //public ActionResult SaveUser(User user)
        //{
        //    user.CurrentCompany = SimadminManager.Get(user.CurrentCompany.CompanyID);
        //    UserManager.Save(user);

        //    return RedirectToAction("GetCompany", "Home", new { id = user.CurrentCompany.CompanyID });
        //}

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult SaveSimadmin(Simadmin simadmin)
        {
            SimadminManager.Save(simadmin);

            return RedirectToAction("Index", "Home");
        }

        public ActionResult GetSimadmin(int id)
        {
            ViewData["Company"] = SimadminManager.Get(id);

            return View();
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
